﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Text;
using FarPoint.Win.Spread;
using Nissen_Dao;

namespace Nissen_Manage.Forms
{
	public class ManageReportService
	{
		/// <summary>
		/// 每天作业数量
		/// </summary>
		public void GetGeresultDay(string savePath)
		{
			ReportDao reportDao = new ReportDao();
			var reportData = reportDao.GetGeresultDay();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "每天工作量";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "件数";
			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
			//Process.Start(excelPath);
		}
		/// <summary>
		/// 小时作业数量
		/// </summary>
		public void GetGeresultDayHour(string savePath)
		{
			ReportDao reportDao = new ReportDao();
			var reportData = reportDao.GetGeresultDayHour();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "小时作业数量";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "小时";
			sheetView.Cells[0, 2].Value = "件数";
			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				sheetView.Cells[i, 2].Value = row[2];
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
		}
		/// <summary>
		/// 用户工作量
		/// </summary>
		public void GetGeresultPerson(string savePath)
		{
			ReportDao reportDao = new ReportDao();
			var reportData = reportDao.GetGeresultPerson();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "用户工作量";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "ID";
			sheetView.Cells[0, 2].Value = "件数";
			sheetView.Cells[0, 3].Value = "ミス";
			sheetView.Cells[0, 4].Value = "正確率";
			sheetView.Cells[0, 5].Value = "出勤時間";
			sheetView.Cells[0, 6].Value = "退勤時間";
			sheetView.Cells[0, 7].Value = "作業時間";
			sheetView.Cells[0, 8].Value = "8--18時";
			sheetView.Cells[0, 9].Value = "18--22時";
			sheetView.Cells[0, 10].Value = "２２時後";
			sheetView.Cells[0, 11].Value = "操作者SSO";
			sheetView.Cells[0, 12].Value = "操作者姓名";
			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				sheetView.Cells[i, 2].Value = row[2];
				sheetView.Cells[i, 3].Value = row[3];
				sheetView.Cells[i, 4].Value = row[4];
				sheetView.Cells[i, 5].Value = row[5];
				sheetView.Cells[i, 6].Value = row[6];
				sheetView.Cells[i, 7].Value = row[7];
				sheetView.Cells[i, 8].Value = row[8];
				sheetView.Cells[i, 9].Value = row[9];
				sheetView.Cells[i, 10].Value = row[10];
				sheetView.Cells[i, 11].Value = row[11];
				sheetView.Cells[i, 12].Value = row[12];
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
		}
		/// <summary>
		/// 用户所有错误, 其中语文错误单独统计
		/// </summary>
		public void GetGeresultPersonMissTotalYuwe(string savePath)
		{
			ReportDao reportDao = new ReportDao();
			var reportData = reportDao.GetGeresultPersonMissTotalYuwe();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "ミス";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "ID";
			sheetView.Cells[0, 2].Value = "漢字ミス";
			sheetView.Cells[0, 3].Value = "数字ミス";
			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				sheetView.Cells[i, 2].Value = row[3];
				sheetView.Cells[i, 3].Value = int.Parse(row[2].ToString()) - int.Parse(row[3].ToString());
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
		}
		/// <summary>
		/// 用户所有工作量, 其中语文单独统计
		/// </summary>
		public void GetGeresultPersonTotalYuwen(string savePath)
		{
			ReportDao reportDao = new ReportDao();
			var reportData = reportDao.GetGeresultPersonTotalYuwen();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "漢字件数";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "ID";
			sheetView.Cells[0, 2].Value = "漢字件数";
			sheetView.Cells[0, 3].Value = "数字件数";

			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				sheetView.Cells[i, 2].Value = row[3];
				sheetView.Cells[i, 3].Value = int.Parse(row[2].ToString()) - int.Parse(row[3].ToString());
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
		}

        /// <summary>
        /// 日本側処理
        /// </summary>
        public void GetGeresultWithNihonSide(string savePath)
        {
            ReportDao reportDao = new ReportDao();
            var reportData = reportDao.GetGeresultWithNihonSide();
            FpSpread spread = new FpSpread();
            var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
            spread.OpenExcel(excelPath);

            SheetView sheetView = spread.Sheets[0];

            sheetView.SheetName = "日本側処理";
            sheetView.Cells[0, 0].Value = "日期";
            sheetView.Cells[0, 1].Value = "ID";
            sheetView.Cells[0, 2].Value = "日本側処理";

            int i = 1;
            foreach (DataRow row in reportData.Rows)
            {
                sheetView.Cells[i, 0].Value = row[0];
                sheetView.Cells[i, 1].Value = row[1];
                sheetView.Cells[i, 2].Value = row[3];
                i++;
            }

            var reportDataDetails = reportDao.GetGeresultWithNihonSideDetails();

            foreach (DataRow row in reportDataDetails.Rows)
            {
                sheetView.Cells[i, 0].Value = row[0];
                sheetView.Cells[i, 1].Value = row[1];
                sheetView.Cells[i, 2].Value = row[2];
                sheetView.Cells[i, 3].Value = row[3];
                sheetView.Cells[i, 4].Value = row[4];
                sheetView.Cells[i, 5].Value = row[5];
                sheetView.Cells[i, 6].Value = row[6];
                sheetView.Cells[i, 7].Value = row[7];
                sheetView.Cells[i, 8].Value = row[8];
                sheetView.Cells[i, 9].Value = row[9];
                sheetView.Cells[i, 10].Value = row[10];
                sheetView.Cells[i, 11].Value = row[11];
                i++;
            }

            spread.SaveExcel(savePath);
            spread.Dispose();
        }

		/// <summary>
		/// 用户校验工作工作量
		/// </summary>
		public void GetGeresultPersonSysUpdId(string savePath)
		{
			ReportDao reportDao = new ReportDao();
            var reportData = reportDao.GetGeresultPersonSysUpdId();
			FpSpread spread = new FpSpread();
			var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
			spread.OpenExcel(excelPath);

			SheetView sheetView = spread.Sheets[0];

			sheetView.SheetName = "検証件数";
			sheetView.Cells[0, 0].Value = "日期";
			sheetView.Cells[0, 1].Value = "ID";
			sheetView.Cells[0, 2].Value = "検証件数";
			int i = 1;
			foreach (DataRow row in reportData.Rows)
			{
				sheetView.Cells[i, 0].Value = row[0];
				sheetView.Cells[i, 1].Value = row[1];
				sheetView.Cells[i, 2].Value = row[2];
				i++;
			}

			spread.SaveExcel(savePath);
			spread.Dispose();
		}

        public void GetGPCountByDate(string savePath,DateTime dtfrom,DateTime dtto)
        {
            ReportDao reportDao = new ReportDao();
            var reportData = reportDao.GetGPCountByDate(dtfrom,dtto);
            FpSpread spread = new FpSpread();
            var excelPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "ExcelTemplate\\ExcelTemplate.xls";
            spread.OpenExcel(excelPath);

            SheetView sheetView = spread.Sheets[0];

            sheetView.SheetName = dtfrom.ToShortDateString()+"_"+dtto.ToShortDateString();
            sheetView.Cells[0, 0].Value = "RegCode";
            sheetView.Cells[0, 1].Value = "ID";
            sheetView.Cells[0, 2].Value = "検証件数";
            int i = 1;
            foreach (DataRow row in reportData.Rows)
            {
                sheetView.Cells[i, 0].Value = row[0];
                sheetView.Cells[i, 1].Value = row[1];
                sheetView.Cells[i, 2].Value = row[2];
                sheetView.Cells[i, 3].Value = row[3];
                i++;
            }

            spread.SaveExcel(savePath);
            spread.Dispose();
        }
	}

}
